{% extends 'user/user_base.html' %}


{% block form %}


    <form action="" method="post">
     {% csrf_token %}
     <div class="form-group">
            {{ form.username.label_tag }}
            {{ form.username }}
            {% if form.username.errors %}
                {% for error in form.username.errors %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>
        <div class="form-group">
            {{ form.email.label_tag }}
            {{ form.email }}

            {% if form.email.errors %}
                {% for error in form.email.errors  %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>
        <div class="form-group">
            {{ form.password.label_tag }}
            {{ form.password }}
                  {% if form.password.errors %}
                {% for error in form.password.errors  %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>
        <div class="form-group">
            {{ form.password2.label_tag }}
            {{ form.password2 }}
            {% if form.password2.errors %}
                {% for error in form.password2.errors  %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>

         <div class="form-group">
             {{ form.captcha.label_tag }}
            {{ form.captcha }}
              {% if form.captcha.errors %}
                {% for error in form.captcha.errors  %}
                    <p class="text-danger">{{ error }}</p>
                {% endfor %}
            {% endif %}
        </div>

        <button type="submit" class="btn btn-default">注册</button>
       <a class="btn btn-default" href="{% url 'user:login' %}" role="button">已有账号，去登录</a>
    </form>

{% endblock %}


{% block js %}
    <script>
    $('.captcha').click(function () {
        $.getJSON("/captcha/refresh/", function (result) {
            $('.captcha').attr('src', result['image_url']);
            $('#id_captcha_0').val(result['key'])
        });
    });
    </script>

{% endblock %}